<template>
  <div class="cascader">
    <el-cascader
      clearable
      v-model="houseid"
      :props="Props"
      :options="buildList"
      @change="changeBuild"
      ref="cascader"
    ></el-cascader>
  </div>
</template>

<script>
import http from "./../../api/building";
export default {
  props: {
    buildId: {
      type: [Number, Array],
    },
    multiple: {
      type: Boolean,
      default: false,
    },
    isRadio: {
      type: Boolean,
      default: false,
    },
  },

  data() {
    return {
      houseid: this.buildId,
      buildList: [],
      buildValue: "",
      Props: {
        checkStrictly: this.isRadio, //是否严格的尊守父子节点不互相关联 //true->代表父和子都可以选择;false->代表只能选一个
        emitPath: false, //只返回选中该节点的值
        multiple: this.multiple,
        value: "id",
        label: "name",
      },
    };
  },
  created() {
    this.getBuildingList();
  },
  methods: {
    async getBuildingList() {
      const { data } = await http.buildingList();
      console.log(data.list);
      this.buildList = data.list;
    },
    changeBuild(val) {
      this.$emit("changeBuildId", val);
      console.log("changeBuildid", val);
    },
  },
  watch: {
    buildId(newVal) {
        console.log(newVal)
      this.houseid = newVal;
    },
  },
};
</script>

<style>
</style>